//
//  RCPointsShopListDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-11-22.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCPointsShopListDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"

@implementation RCPointsShopListItem

@synthesize itemID = _itemID;
@synthesize itemTitle = _itemTitle;
@synthesize itemDesc = _itemDesc;
@synthesize itemScore = _itemScore;
@synthesize itemPicUrl = _itemPicUrl;
@synthesize itemChangeTimes = _itemChangeTimes;
@synthesize itemChangePoints = _itemChangePoints;

-(id)init{
    self = [super init];
    if (self) {
        _itemID = nil;
        _itemTitle = nil;
        _itemDesc = nil;
        _itemScore = 0;
        _itemPicUrl = nil;
        _itemChangeTimes = nil;
        _itemChangePoints = nil;
    }
    return self;
}

-(void)dealloc{
    self.itemID = nil;
    self.itemTitle = nil;
    self.itemDesc = nil;
    self.itemPicUrl = nil;
    self.itemChangeTimes = nil;
    self.itemChangePoints = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    RCPointsShopListItem *retObject = nil;
    retObject = [[RCPointsShopListItem alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
    retObject.itemID = [data stringValueForKey:@"goodsid" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemTitle = [data stringValueForKey:@"title" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemDesc = [data stringValueForKey:@"description" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemPicUrl = [data stringValueForKey:@"picurl" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemChangeTimes = [data stringValueForKey:@"changetimes" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemChangePoints = [data stringValueForKey:@"points" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.itemScore = [data intValueForKey:@"score" defaultValue:0];
    
    return [retObject autorelease];
}

@end

@implementation RCPointsShopListDataModel

@synthesize total = _total;
@synthesize itemListArray = _itemListArray;

-(id)init{
    self = [super init];
    if (self) {
        _total = 0;
        _itemListArray = nil;
    }
    return self;
}


-(void)dealloc{
    self.itemListArray = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    
    NSDictionary *dict = [data dictionaryValueForKey:@"data" defaultValue:nil];
    if (nil == dict) {
        return nil;
    }
    
    RCPointsShopListDataModel *retObject = nil;
    retObject = [[RCPointsShopListDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    
    NSArray *dictArray = [dict arrayValueForKey:@"items" defaultValue:nil];
    if (nil == dictArray || [dictArray count] == 0) {
        return [retObject autorelease];
    }
    
    NSMutableArray *itemTempArray = [[NSMutableArray alloc]init];
    for (int i = 0; i < [dictArray count]; i++) {
        NSDictionary *itemDict = [dictArray safeObjectAtIndex:i];
        if (nil == itemDict) {
            continue;
        }
        
        RCPointsShopListItem *item = [RCPointsShopListItem parseDataFromJSON:itemDict];
        if (nil == item) {
            continue;
        }
        [itemTempArray addObject:item];
    }
    
    retObject.itemListArray = [NSArray arrayWithArray:itemTempArray];
    [itemTempArray release];
    
    return [retObject autorelease];
}
@end
